package com.nercl.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.nercl.dao.DeptDao;
import com.nercl.dao.impl.DeptDaoImpl;
import com.nercl.model.Dept;

/**
 * Servlet implementation class AddDeptServlet
 */
@WebServlet("/AddDeptServlet")
public class AddDeptServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddDeptServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(request,response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.setCharacterEncoding("utf-8");//设置response编码方式
		request.setCharacterEncoding("utf-8");//设置request编码方式
		String depname = request.getParameter("deptName");//获得页面传递过来的数据
		System.out.println("+++++传递过来的值:=="+depname);
		Dept dept = new Dept();
		dept.setDepname(depname);//把获得的页面数据设置到Dept对象中
		DeptDao deptDao = new DeptDaoImpl();
		deptDao.save(dept);//调用实现类DeptDaoImp的addDept方法
		response.sendRedirect("IndexServlet");//页面重定向到IndexServlet中
	}
}
